# GPL3 or later

# This is the initialization script. It will start other scripts.
# I could use threading ( since all of them are written in python ) but it
# seems to be very broken using threading. So instead I will do it as separate
# scripts. Thought the users shouldn't care about it very much.

import time
import json
import subprocess

from modules.ui import *
from modules import setup

# Modules that are required might be missing

try:
    import simplematrixbotlib as botlib
except:
    center("Missing module 'simplematrixbotlib'!", "bdrd")    
    print("Please use: sudo pip install simplematrixbotlib")
    exit()

try:
    import youtube_dl
except:
    center("Missing module 'youtube_dl'!", "bdrd")    
    print("Please use: sudo pip install --upgrade youtube_dl")
    exit()

# Setting up the program
    
try:
    with open('stuff.json') as json_file: 
        stuff = json.load(json_file)
except:
    setup.run()
    
subprocess.Popen(["gnome-terminal", "--",  "python3", "modules/matrix_bot.py"])
subprocess.Popen(["gnome-terminal", "--",  "python3", "modules/http_server.py"])
time.sleep(2)


interface = subprocess.Popen(["gnome-terminal","--hide-menubar","--full-screen", "--", "python3", "modules/interface.py"])
